/**
 * @file
 * @author  michal.nezerka@gmail.com
 * @brief   GPX file Declaration
 *
 * Definition of GeoUtils class and all related classes
 *
 * https://msdn.microsoft.com/en-us/library/bb259689.aspx
 * http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
 */

#ifndef WWGEOUTILS_H
#define WWGEOUTILS_H

#include <vector>
#include <wx/xml/xml.h>

namespace wildwood
{
class GeoPos
{
    public:
        GeoPos(double lat = 0, double lon = 0) : mLat(lat), mLon(lon) { };
        friend std::ostream &operator<<(std::ostream& output, const GeoPos& pos);
        int operator==(const GeoPos &pos) const;
        void setLat(const double lat) { mLat = lat; };
        double getLat() const { return mLat; };
        void setLon(const double lon) { mLon = lon; };
        double getLon() const { return mLon; };

    private:
        double mLat;
        double mLon;
};

struct TilePos
{
    TilePos(int x = 0, int y = 0, int inX = 0, int inY = 0, int zoom = 0)
        : mX(x), mY(y), mInX(inX), mInY(inY), mZoom(zoom) { };
    int mX;
    int mY;
    int mInX;
    int mInY;
    int mZoom;

    wxString toString();
    bool isValid() { return mX >= 0 && mY >= 0 && mInX >= 0 && mInY >= 0 && mX < pow(2, mZoom) && mY < pow(2, mZoom); };
    void move(const int deltaX, const int deltaY);
    void zoomIn(const unsigned int steps = 1);
    void zoomOut(const unsigned int steps = 1);

    TilePos& operator=(const TilePos &pos);
    int operator==(const TilePos &pos) const;
    int operator<(const TilePos &pos) const;
    friend std::ostream &operator<<(std::ostream& output, const TilePos& pos);
};

class GeoUtils
{
public:
    static const int TILE_SIZE = 256;

    GeoUtils() { };
    virtual ~GeoUtils() { };
    static TilePos gpsPos2TilePos(const GeoPos pos, const unsigned int zoom);
    static GeoPos tilePos2GeoPos(const TilePos pos);

private:
};

} // namespace

#endif // WWGEOUTILS_H
